<template>
	<view class="main">
		<view class="list-main v-box">
			<block v-if="listrow.length>0">
				<view class="row-item" v-for="(item,index) in listrow" :key="index" @click="warninfo(item)">
					<view class="img">
						<image :src="item.img"></image>
					</view>
					<view class="text-item">
						<label>{{cutstr(item.title,35)}}</label>

						<text>{{item.createTime}}</text>
					</view>
				</view>
			</block>
			<block v-if="listrow.length == 0">
				<view class="empty-img">
					<image src="http://xgr.oss-cn-hangzhou.aliyuncs.com/icon/images/icon50.png"></image>
					<label>暂无内容</label>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
import Index from "@/common/index-model.js"
let index = new Index();
let that = null;
export default {
	data() {
		return {
			listrow: []
		}
	},
	onLoad() {
	   this.getListRow()	
	},
	onPullDownRefresh() {
		this.getListRow();
		setTimeout(function () {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	methods: {
		warninfo(item) {
			let url = './info?id='+item.id
			index.navigate_to(url)
		},
		getListRow() {
			index.getPublicMember({},'client/public/listInfomations','get',res=>{
				if(res.data.code == 200 && res.data.success){
					this.listrow =  res.data.result
				}else{
					this.listrow = []
				}
			})
		},
		cutstr(str, len) {
			var str_length = 0;
			var str_len = 0;
			var str_cut = new String();
			str_len = str.length;
			for (var i = 0; i < str_len; i++) {
				var a = str.charAt(i);
				str_length++;
				if (escape(a).length > 4) {
					//中文字符的长度经编码之后大于4  
					str_length++;
				}
				str_cut = str_cut.concat(a);
				if (str_length >= len) {
					str_cut = str_cut.concat("...");
					return str_cut;
				}
			}
			//如果给定字符串小于指定长度，则返回源字符串；  
			if (str_length < len) {
				return str;
			}
		},
	}
}	
</script>

<style>
@import url("@/static/css/publics.css");	
@import url("@/static/css/news.css");	
</style>